From cc91520e76079555bee24360d42610b7cbc246b3 Mon Sep 17 00:00:00 2001
From: Mark Liversedge <liversedge@gmail.com>
Date: Fri, 17 Jan 2020 12:30:29 +0000
Subject: View on Strava

.. when data is downloaded from strava we now set the metadata
   tag "StravaID" to the id of the activity on Strava.

.. On RideSummary a link is added at the bottom to view the activity
   on Strava if the "StravaID" is set.

.. if the user clicks on the link the summary is replaced with the
   strava page for the ride:
      e.g. https://www.strava.com/activities/962515512

.. this is part of a couple of updates to comply with the Strava
   guidelines for consumption of the Strava v3 API, see:
      https://developers.strava.com/guidelines/

diff --git a/src/Charts/RideSummaryWindow.cpp b/src/Charts/RideSummaryWindow.cpp
index 1906ef1f3..37de8244d 100644
--- a/src/Charts/RideSummaryWindow.cpp
+++ b/src/Charts/RideSummaryWindow.cpp
@@ -1517,6 +1517,12 @@ RideSummaryWindow::htmlSummary()
             summary += " <li>" + i.next();
         summary += "</ul>";
     }
+
+    // add link to view on Strava if was downloaded from there (StravaID will be set)
+    if (ridesummary && rideItem && rideItem->ride() && rideItem->ride()->getTag("StravaID","") != "") {
+        summary += "<a href=\"https://www.strava.com/activities/" + rideItem->ride()->getTag("StravaID","") + "\">View on Strava</a>";
+    }
+
     summary += "<br></center>";
 
     return summary;
diff --git a/src/Cloud/Strava.cpp b/src/Cloud/Strava.cpp
index 0b339ac98..fe03e9eba 100644
--- a/src/Cloud/Strava.cpp
+++ b/src/Cloud/Strava.cpp
@@ -859,6 +859,9 @@ Strava::prepareResponse(QByteArray* data)
         // 1s samples with start time
         RideFile *ride = new RideFile(starttime.toUTC(), 1.0f);
 
+        // set strava id in metadata (to show where we got it from - to add View on Strava link in Summary view
+        if (!each["id"].isNull()) ride->setTag("StravaID",  QString("%1").arg(each["id"].toVariant().toULongLong()));
+
         // what sport?
         if (!each["type"].isNull()) {
             QString stype = each["type"].toString();
